package com.hualan.sfzy.service.counselor.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.CounselorOrder;
import com.hualan.sfzy.mapper.counselor.CounselorOrderMapper;
import com.hualan.sfzy.service.counselor.CounselorOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CounselorOrderImpl implements CounselorOrderService {
    @Autowired
    private CounselorOrderMapper mapper;

    @Override
    public int add(CounselorOrder entity) {
        return mapper.insert( entity);
    }

    @Override
    public int edit(CounselorOrder entity) {
        return mapper.update( entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete( id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch( ids);
    }

    @Override
    public List<CounselorOrder> find() {
        return mapper.select( null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CounselorOrder entity) {
        //分页业务
        PageHelper.startPage(pageNum, pageSize);
        List<CounselorOrder> list = mapper.select(entity);
        PageInfo<CounselorOrder> pageInfo = new PageInfo<>(list);
//1.当前页面数据（数据列表）2.此次查询的总记录数
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public CounselorOrder findById(Integer id) {
        return mapper.selectById( id);
    }
}
